#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int>v(12);
void solve()
{
    int n,m;
    cin>>n>>m;
    int x,y,z;
    for(int i=1;i<=m;i++)
    {
        cin>>x>>y>>z;
        if(x>=v[n]&&y>=v[n]&&z>=v[n])
        {
            if(x>=v[n]+v[n-1]||y>=v[n]+v[n-1]||z>=v[n]+v[n-1])cout<<1;
            else cout<<0;
        }
        else cout<<0;
    }
    cout<<endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T=1;
    cin>>T;
    v[1]=1,v[2]=2;
    for(int i=3;i<=11;i++)v[i]=v[i-1]+v[i-2];
    while(T--)
    {
       solve();
    }
    return 0;
}